import { Component, Output, EventEmitter } from '@angular/core';
import { NavController, NavParams, ModalController, ActionSheetController, IonNav } from '@ionic/angular';
// import { PersonInfo } from '../my/person-info/person-info';
// import { About } from '../my/about/about';
// import { SetPage } from '../my/settings/settings';
// import { ScorePage } from '../my/score/score';
// import { TaskPage } from '../my/task/task';
// import { PersonalManagerPage } from '../my/personal-manager/personal-manager';
import { CacheService } from '@services/cache.service';
import { PicUploadService } from '@services/picUpload.service';
import { Router } from '@angular/router';
import { AlarmTabComponent } from '@components/alarm-tab/alarm-tab';
import { Page404 } from '@pages/home/page404/page404';


/**
 * Generated class for the TestPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-my',
  templateUrl: 'my.html',
  styleUrls: ['my.scss'],
})
export class MyPage {
  // 默认图片
  person = {
    UserName: '',
    imgStyle: {
      'background-image': 'url("assets/imgs/default.png")'
    }
  };
  userInfo;
  // @Output()
  // successScaned: EventEmitter<any> = new EventEmitter();
  // @Output()
  // wrongScaned: EventEmitter<any> = new EventEmitter();

  // ionViewDidLoad() {
  //   console.log('ionViewDidLoad TestPage');
  // }

  // open(format: boolean = false) {
  //   const modal = this.modalCtrl.create('QRScannerModal');

  //   modal.onDidDismiss(qrCode => {
  //     if (lodash.isNil(qrCode)) {
  //       return this.wrongScaned.emit();
  //     }
  //     const response = qrCode;
  //     return this.successScaned.emit(response);
  //   });

  //   modal.present();
  // }

  // private formatScheme(qrCode: any) {
  //   if (lodash.isObject(qrCode)) {
  //     return qrCode;
  //   } else {
  //     this.wrongScaned.emit();
  //   }
  // }


  permission = {
    'profile/task': true,
    'profile/integral': true,
    'profile/card': true,
    'profile/cardsta': true,
    'profile/share': true
  };

  constructor(public navCtrl: NavController,
    public cache: CacheService,
    private picUploadService: PicUploadService,
    private router: Router,
  ) {
  }

  ionViewWillEnter() {
    const elements = document.querySelectorAll('ion-tab-bar');
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'flex';
      });
    }
    this.person.UserName = this.cache.userinfo.userName;
    // 设置头像
    this.picUploadService.getAvatar().subscribe(imgdata => {
      this.person.imgStyle = { 'background-image': 'url(' + imgdata.url + ')' };
    });
  }

  ionViewWillLeave() {
    const elements = document.querySelectorAll('ion-tab-bar');
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'none';
      });
    }
  }


  toPage(data) {
    console.log(data);
    // this.router.navigate(['tabs/my/' + data]);
    this.navCtrl.navigateForward(['tabs/my/' + data]);
    // this.nav.push(Page404);
  }

  // toShare() {
  //   const actionSheet = this.actionSheetCtrl.create({
  //     cssClass: 'take-share',
  //     buttons: [
  //       {
  //         text: '微信好友',
  //         role: 'destructive',
  //         handler: () => {
  //         }
  //       }, {
  //         text: '发朋友圈',
  //         role: 'destructive',
  //         handler: () => {
  //         }
  //       }, {
  //         text: '取消',
  //         role: 'cancel',
  //         handler: () => {
  //           console.log('Cancel clicked');
  //         }
  //       }
  //     ]
  //   });
  //   actionSheet.present();
  // }
  toShare() {
  }
}

